<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>18-vue组件的data</title>
</head>

<body>

  <div id="app">
    <cpn></cpn>
    <cpn2></cpn2>
  </div>

  <template id="cpn1">
    <div>
      <h1>{{title}}</h1>
      <p>我是内容，哈哈哈哈</p>
    </div>
  </template>

  <template id="cpn2">
    <div>
      <h1>{{title1}}</h1>
      <p>我是内容，哈哈哈哈</p>
    </div>
  </template>

  <script src="./js/vue.js"></script>
  <script>
    // 全局组件注册
    Vue.component(
      "cpn", {
      template: "#cpn1",
      data() { // data为什么必须是函数
        return {
          title: "我是title"
        }
      }
    })

    const app = new Vue({
      el: "#app",
      components: {
        cpn2: { // 子组件注册
          template: "#cpn2",
          data() {
            return {
              title1: "我是content"
            }
          }
        },
      }
    })
  </script>
</body>

</html>